package cn.wolfcode.shop.mapper;

import cn.wolfcode.shop.domain.SeckillGood;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SeckillGoodMapper {

    @Select("select * from t_seckill_goods")
    List<SeckillGood> list();

    @Select("select * from t_seckill_goods where id = #{id}")
    SeckillGood selectByPrimaryKey(Long seckillGoodId);

    @Update("update t_seckill_goods set stock_count = stock_count - 1 where id = #{seckillGoodId} and stock_count > 0")
    int reduceStock(Long seckillGoodId);

    @Select("select stock_count from t_seckill_goods where id = #{seckillGoodId}")
    int getStock(Long seckilGoodId);

    @Update("update t_seckill_goods set stock_count = stock_count + 1 where id = #{seckillGoodId}")
    void incrStock(Long seckillGoodId);
}
